package com.twotwoshop.service.goods.controller;


import com.twotwoshop.domin.category.dtos.CategoryDto;
import com.twotwoshop.domin.common.dtos.ResponseResult;
import com.twotwoshop.service.goods.service.ProductCategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods/category")
@RequiredArgsConstructor
public class ProductCategoryController {

    private final ProductCategoryService categoryService;


    /**
     * 获取分类列表
     */
    @GetMapping("/list")
    public ResponseResult list() {
        return categoryService.list();
    }


    /**
     * 添加分类
     */
    @PostMapping()
    public ResponseResult add(@Validated @RequestBody CategoryDto categoryDto) {
        return categoryService.add(categoryDto);
    }

    /**
     * 修改分类
     */
    @PutMapping("/{id}")
    public ResponseResult update(@PathVariable Long id, @Validated @RequestBody CategoryDto categoryDto) {
        categoryDto.setId(id);
        return categoryService.update(categoryDto);
    }

    /**
     * 删除分类
     */
    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Long id) {
        return categoryService.delete(id);
    }


    /**
     * 获取分类树
     */
    @GetMapping("/tree")
    public ResponseResult tree() {
        return categoryService.tree();
    }

    /**
     * 修改分类状态
     */
    @PutMapping("/{id}/status")
    public ResponseResult updateStatus(
            @PathVariable Long id,
            @RequestParam Integer status) {
        return categoryService.updateStatus(id, status);
    }
}